package com.fh.modules.system.service.impl;

import javax.annotation.Resource;

import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import com.fh.common.constant.CommonConstant;
import com.fh.common.web.impl.AbstractServiceImpl;
import com.fh.modules.system.entity.SysLog;
import com.fh.modules.system.entity.SysLogQuery;
import com.fh.modules.system.mapper.SysLogMapper;
import com.fh.modules.system.mapper.SysLogQueryMapper;
import com.fh.modules.system.service.ISysLogService;
import com.fh.modules.system.vo.LoginInfoVO;

/**
 * @author Qiu,Junda
 * @date 2019年4月3日
 * @description 系统日志表 服务实现类
 */
@Service
public class SysLogServiceImpl extends AbstractServiceImpl<SysLogMapper, SysLog> implements ISysLogService {

	@Resource
	private SysLogMapper sysLogMapper;
	@Resource
	private SysLogQueryMapper sysLogQueryMapper;
	
	@Override
	public boolean save(SysLog entity) {
		if(entity.getLogType()==CommonConstant.LOG_TYPE_QUERY) {
			SysLogQuery sysLogQuery=new SysLogQuery();
			BeanUtils.copyProperties(entity, sysLogQuery);
			sysLogQueryMapper.insert(sysLogQuery);
		}
		return super.save(entity);
	}
	
	/**
	 * @功能：清空所有日志记录
	 */
	@Override
	public void removeAll() {
		sysLogMapper.removeAll();
	}

	@Override
	public Long findTotalVisitCount() {
		return sysLogMapper.findTotalVisitCount();
	}

	@Override
	public Long findTodayVisitCount() {
		return sysLogMapper.findTodayVisitCount();
	}

	@Override
	public Long findTodayIp() {
		return sysLogMapper.findTodayIp();
	}

	@Override
	public LoginInfoVO getLoginInfo() {
		LoginInfoVO loginInfoVO=new LoginInfoVO();
		loginInfoVO.setTodayIp(this.findTodayIp());
		loginInfoVO.setTodayVisitCount(this.findTodayVisitCount());
		loginInfoVO.setTotalVisitCount(this.findTotalVisitCount());
		return loginInfoVO;
	}

}
